﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LocalizedSample
{
    public class LocalizationSet<T, TL> : HashSet<TL> where TL : Localization<T>, new()
    {

        public LocalizationSet()
        {
        }

        public TL this[int lcid] 
        {
            get
            {
                TL result = this.Where(m => m.LCID == lcid).FirstOrDefault();
                if (result == null && lcid == LocalizationContext.CurrentLCID)
                {
                    result = new TL();
                    this.Add(result);
                    return result;
                }

                return result;
            }
            set
            {
                value.LCID = lcid;
                
                this.Add(value);
            }
        }

        public TL Current
        {
            get { return this[LocalizationContext.CurrentLCID]; }
            set { this[LocalizationContext.CurrentLCID] = value; }
        }
    }
}
